/**
 * Created by Administrator on 2016/8/11.
 */
define(["require",'config/appregister',"business/workSkill/services/httpServices"],function(require,app,httpServices){
    app.controller('workListCtrl',function($scope,$state,$rootScope){
       $scope.$parent.isDetailPage = false;
        $scope.$parent.isMainpage = true;
        $scope.linkSearch=function(name){
            $rootScope.GLOBALKEYWORD =  name;
            sessionStorage.searchKeyWord = name;
            $state.transitionTo("search.skill", {}, {
                reload: true, inherit: false, notify: true
            });
        }
        $scope.linkfile=function(id){
            $state.go("eng.techdetail",{fileId:id})
        }
        /*一级分类*/
       $scope.goto1 = function(ctrl){
			$state.go(ctrl,{},{reload:true})
		}
       $scope.goto = function(item,Id,ctrl){
			$state.go(ctrl,{postbarId:Id})
		}
        $scope.goTo = function(item){
        	$state.go("eng.workDetailsCtrl",{skillId:item.skillId})
        }
        function oneClass(){
            var req ={
                type:"GET",
                uri:"getTopCategory",
                data:{}
            };
            httpServices.oneClass(req).success(function(response){
                $scope.$apply(function(){
                    $scope.worktab=response.data
                })
            });
        }

        $scope.listParams = {
            currentTcId: "",
            download: false,
            time: false,
            pageNo: 1,
            pageSize:10,
            all: false,
            typeId: "",
            scId: "",
            dcId: "",
            keyWord:"",
            //dcName scName 用于加入缓存 在详情中显示面包树导航
            dcName:"",
            scName:""
        };
        $scope.list = [];
        function getListModel(){
            $scope.paginationConf = {
                currentPage: $scope.listParams.pageNo,
                totalItems: $scope.totalItem,
                //每页预览条数
                itemsPerPage:$scope.listParams.pageSize,
                //分页总数
                numberOfPages:Math.ceil($scope.totalItem/$scope.listParams.pageSize),
                // 实际分页长度
                pagesLength:5,
                perPageOptions: [10, 20, 30, 40, 50],
                onChange: function (currentPage) {
                    if(currentPage){
                        $scope.paginationConf.currentPage = currentPage;
                    }
                    $scope.list = [];
                    $scope.listParams.pageNo = $scope.paginationConf.currentPage;
                    getConList();

                }
            };
        }

        if(sessionStorage.worlListId){
            oneClass();
            $scope.current=sessionStorage.worlListId;
            function getConList2(){
                var req ={
                    type:"GET",
                    uri:"",
                    data:{
                        tcId:sessionStorage.worlListId,
                        visitCount:"false",
                        publishTime:"false",
                        pageNo:$scope.listParams.pageNo,
                        pageSize:$scope.pageSize,
                        all:"false",
                        count:"6"
                    }
                };
                httpServices.getCOnlist(req).success(function(response){
                    $scope.$apply(function(){
                        $scope.ConList = response.data.list;
                        $scope.skillFileVoList = response.data.list.skillFileVoList;
                        $scope.totalItem = response.data.Pagination.totalCount;
                        getListModel();
                    })
                });

            }
            getConList2();
            /*分页效果*/
            $scope.list = [];
            function getListModel(){
                $scope.paginationConf = {
                    currentPage: $scope.listParams.pageNo,
                    totalItems: $scope.totalItem,
                    //每页预览条数
                    itemsPerPage:$scope.listParams.pageSize,
                    //分页总数
                    numberOfPages:Math.ceil($scope.totalItem/$scope.listParams.pageSize),
                    // 实际分页长度
                    pagesLength:5,
                    perPageOptions: [10, 20, 30, 40, 50],
                    onChange: function (currentPage) {
                        if(currentPage){
                            $scope.paginationConf.currentPage = currentPage;
                        }
                        $scope.list = [];
                        $scope.listParams.pageNo = $scope.paginationConf.currentPage;
                        getConList2();

                    }
                };
            }
        }else{
            $scope.current = false;
            oneClass();
            getConList();
        }
        /*默认列表内容*/
        function getConList(){
            var req ={
                type:"GET",
                uri:"",
                data:{
                    all:"false",
                    pageNo:$scope.listParams.pageNo,
                    visitCount:false,
                    publishTime:true,
                    pageSize:$scope.pageSize,
                    count:"6"
                }
            };
            httpServices.getCOnlist(req).success(function(response){
                $scope.$apply(function(){
                    $scope.ConList = response.data.list;
                    var data = response.data.list;
                    $scope.totalItem = response.data.Pagination.totalCount;
                    var order = "startTime";//默认开始时间显示
                    $scope.col = order;
                    $scope.desc = 0;
                    getListModel();
                })
            });
        }


        /*点击一级分类切换*/
            $scope.switchData =  function(item){
                console.log(item)
                getListModel();
                $scope.peopecolor = false;
                $scope.isDisabled = true;
                $scope.listParams.pageNo =1;
                var switchId = item.tcId;
                $scope.current =  item.tcId;
                var req ={
                    type:"GET",
                    uri:"",
                    data:{
                        tcId:switchId,
                        visitCount:$scope.peopecolor,
                        publishTime:$scope.isDisabled,
                        pageNo:$scope.listParams.pageNo,
                        pageSize:$scope.pageSize,
                        all:"false",
                        count:"6"
                    }
                };
                httpServices.getCOnlist(req).success(function(response){
                    $scope.$apply(function(){
                        $scope.ConList = response.data.list;
                        $scope.skillFileVoList = response.data.list.skillFileVoList;
                        $scope.totalItem = response.data.Pagination.totalCount;
                        getListModel();
                    })
                });
            }
        //点击全部执行默认操作
        $scope.WorkAll = function(){
            sessionStorage.removeItem("worlListId")
            $scope.peopecolor = false;
            $scope.isDisabled = true;
            $scope.current=false;
            getConList();
        }
        /*下载排行*/
        function downlaodRank(){
            var req ={
                type:"GET",
                uri:"getDownLoadRank?count=8",
                data:{}
            };
            httpServices.getDownd(req).success(function(response){
                $scope.$apply(function(){
                    $scope.RankCon = response.data.list;
                })
            });
        }
        downlaodRank();

       
        /*点击每个跳转*/
        $scope.linkSwitch = function(item){
            $state.go("eng.workDetailsCtrl",{skillId:item.skillId})
        }


        /*排序*/

        $scope.isDisabled = true;
        $scope.peopecolor = false;
        $scope.DateColor = function(){
            if($scope.current == false){
                $scope.current = "";
            }
         
            $scope.isDisabled = !$scope.isDisabled;
            var req ={
                type:"GET",
                uri:"",
                data:{
                    all:"false",
                    pageNo:$scope.listParams.pageNo,
                    visitCount: $scope.peopecolor,
                    publishTime:$scope.isDisabled,
                    pageSize:$scope.pageSize,
                    count:"6",
                    tcId:$scope.current
                }
            };
            httpServices.getCOnlist(req).success(function(response){
                $scope.$apply(function(){
                    $scope.ConList = response.data.list;
                    var data = response.data.list;
                    $scope.totalItem = response.data.Pagination.totalCount;
                    var order = "startTime";//默认开始时间显示
                    $scope.col = order;
                    $scope.desc = 0;
                    getListModel();
                })
            });
        };
       
        $scope.peopleColor=function(){
          
            $scope.peopecolor = !$scope.peopecolor;
            var req ={
                type:"GET",
                uri:"",
                data:{
                    all:"false",
                    pageNo:$scope.listParams.pageNo,
                  	visitCount: $scope.peopecolor,
                    publishTime:$scope.isDisabled,
                    pageSize:$scope.pageSize,
                    count:"6"
                }
            };
            httpServices.getCOnlist(req).success(function(response){
                $scope.$apply(function(){
                    $scope.ConList = response.data.list;
                    var data = response.data.list;
                    $scope.totalItem = response.data.Pagination.totalCount;
                    var order = "startTime";//默认开始时间显示
                    $scope.col = order;
                    $scope.desc = 0;
                    getListModel();
                })
            });
        };
        /*字体八个颜色*/
        $scope.content = [
            {color:"#fe0000"},
            {color:"#fea100"},
            {color:"#f7f036"},
            {color:"#71cf0d"},
            {color:"#7edad9"},
            {color:"#83a6ef"},
            {color:"#f736da"},
            {color:"#fca5a5"}
            ]
        /*边框9个颜色*/
        $scope.border=[
            {
                border:"1px solid #35b558",
                color:"#35b558"
            },
            {
                border:"1px solid #cccccc",
                color:"#cccccc"
            },
            {
                border:"1px solid #ec251f",
                color:"#ec251f"
            },
            {
                border:"1px solid #35b558",
                color:"#35b558"
            },
            {
                border:"1px solid #cccccc",
                color:"#cccccc"
            },
            {
                border:"1px solid #ec251f",
                color:"#ec251f"
            },
            {
                border:"1px solid #35b558",
                color:"#35b558"
            },
            {
                border:"1px solid #cccccc",
                color:"#cccccc"
            },
            {
                border:"1px solid #ec251f",
                color:"#ec251f"
            }

        ]
    })
});


